﻿<cfscript>
/** 
* ORM Subject
* 
* @hint "Hibernate persistenter t_subject. 学校专业设置的基本数据项" 
* 
*/ 

component 
	displayname="public.service.orm.senate.Subject" 
	output=false 
	persistent=true 
	selectBeforeUpdate=true dynamicInsert=true dynamicUpdate=true 
	cacheuse="Transactional" 
	entityname="Subject" 
	table="t_subject"
	{

	property type="string" name="SubjectID" column="sbj_id" fieldtype="id" generator="assigned" hint="专业号";
	
	property type="string" name="SubjectName" column="sbj_name" hint="专业名称";
	property type="string" name="SubjectShortName" column="sbj_short" hint="专业简称";
	property type="string" name="SubjectEnglish" column="sbj_english" hint="专业英文名称";
	property type="string" name="SubjectDirection" column="sbj_direction" hint="专业方向号";
	property type="numeric" name="SchoolingLength" column="schooling_length" hint="学制";
	property type="string" name="SubjectCode" column="subject_code" hint="本专科专业码";
	property type="string" name="TermStart" column="term_start" hint="招生学期";	
	property type="string" name="StudentLevel" column="level_code" hint="培养层次代码";	

	property name="Charges" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="sbj_id" cfc="GraduateCharge" hint="专业学分收费设置";
	property name="FormClasses" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="sbj_id" cfc="FormClass" hint="（行政）班级";
	property name="GraduateConditions" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="sbj_id" cfc="GraduateCondition" hint="各专业年级的毕业学分、学时要求";
	property name="GraduateProgresses" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="sbj_id" cfc="GraduateProgress" hint="专业学分修读进程设置";
	property name="ProgramSchemas" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="sbj_id" cfc="ProgramSchema" hint="各年级专业的培养方案";
	property name="ProgramSchemaModifies" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="sbj_id" cfc="ProgramSchemaModify" hint="培养方案更改";
	property name="ProgramSchemaAudits" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="sbj_id" cfc="ProgramSchemaAudit" hint="培养方案修订情况统计";

	property name="StudentSecondDegrees" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="sbj_id" cfc="StudentSecondDegree" hint="双学位修读信息";
	property name="StudentSecondSubjectes" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="sbj_id" cfc="StudentSecondSubject" hint="专业辅修信息";

	property name="Institute" fieldtype="many-to-one" fkcolumn="institute_id" cfc="Institute"  hint="院系所号";
	property name="LearningBranch" fieldtype="many-to-one" fkcolumn="b_id" cfc="LearningBranch"  hint="学科门类码";

	/**
	* @hint "自定义专业方向生成规则"
	* 
	* @SubjectID "专业代码"
	*/
	public string function getNextDirectionID( required string SubjectID ) output=false {
		
		var nextID = arguments.SubjectID & "1";
		var checkArray = ORMExecuteQuery("select SubjectID from Subject 
											where SubjectID like :condition 
											order by SubjectID desc", {condition = arguments.SubjectID & "_"}, { maxResults=1 });
		/* 
			专业方向生成规则 
			
			专业方向代码为6位, 前五位专业代码 余下1位为流水号 换言之 每一个专业至多设置9个专业主修方向
			
		*/
		if (arrayLen(checkArray)) {
			/* 创建一个追加id */
			nextID = arguments.SubjectID & (right(checkArray[1], 1) + 1);
		}
		
		return nextID;
	}
	
	/**
	* @hint "自定义主键规则"
	* 
	* @StudentLevel "本专科代码"
	* @TermStart "招生学期"
	*/
	public string function getNextID( required string StudentLevel, required string TermStart ) output=false {
		
		var nextID = arguments.StudentLevel & arguments.TermStart & numberFormat(1, "0__");
		var checkArray = ORMExecuteQuery("select SubjectID from Subject 
											where SubjectID like :condition 
											order by SubjectID desc", {condition = arguments.StudentLevel & arguments.TermStart & "___"}, { maxResults=1 });
		
		/* 
			主键生成规则 
			
			专业代码为5位, 第一位 本专科 第二位 招生学期 余下3位为流水号 换言之 每一个学校至多设置999个招生专业
			
		*/
		if (arrayLen(checkArray)) {
			/* 创建一个追加id */
			nextID = arguments.StudentLevel & arguments.TermStart & numberFormat((right(checkArray[1], 3) + 1), "0__");
			
		}

		return nextID;
	}
	
}

</cfscript>